home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 754 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Static member functions and overloading resolution
  5. Date: 18 Mar 1996 09:38:16 PST
  6. Organization: Sun Microsystems Inc., Mountain View, CA
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4ifv63$qsk@engnews1.Eng.Sun.COM>
  9. References: <4i9rbn$fgj@cri.ens-lyon.fr>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 17 Mar 1996 02:59:15 GMT
  12. X-Newsreader: NN version 6.5.0 #21 (NOV)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMU2fsEy4NqrwXLNJAQGJVAIAzN4fvIiF8ISkyre7m9e9eY1Rr/RWJQb7
  15.     ieJDpIXBrK2vv21SJr10pqiHKMxLgEu4dP84jeVjiabCer6bfG0ExQ==
  16.     =d89M
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. elesueur@ens-lyon.fr (Emmanuel Lesueur) writes:
  20.  
  21. >Consider the following situation:
  22.  
  23. >    class A {
  24. >    public:
  25. >        void f(int);
  26. >        static void f(char);
  27. >    };
  28.  
  29. >    class B : public A {
  30. >    };
  31.  
  32. >    void foo(B& b,char c) {
  33. >        b.f(c);
  34. >    }
  35.  
  36. >Here, the candidates functions for overloading resolution are
  37. >f(const A&,int) and f(?,char) where '?' matches any type,
  38. >and the call arguments have types B& and char.
  39. >The first candidate needs a conversion from B& to const A& for the
  40. >first argument while the second is an exact match. The second
  41. >candidate has an exact match for the first argument while the
  42. >second requires a char->int promotion. Therefore, the call
  43. >is ambiguous.
  44.  
  45. According to the way you wrote your example, the first
  46. candidate is the non-static f(int). It requires a conversion
  47. from B& to A& on the first argument, and a promotion of char
  48. to int on the second. The second candidate, static f(char), has
  49. an exact match on any first argument (since it is a fiction anyway),
  50. and an exact match (char to char) on the second argument.
  51. There is no ambiguity, and the static f(char) should be selected.
  52. --
  53. Steve Clamage, stephen.clamage@eng.sun.com
  54. ---
  55. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  56.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  57.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  58.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  59.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  60. ]
  61.